package com.ruoyi.function.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.function.domain.Orders;
import com.ruoyi.function.domain.PayParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.function.domain.SysTopUp;
import com.ruoyi.function.service.ISysTopUpService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统充值订单Controller
 *
 * @author ruoyi
 * @date 2025-03-20
 */
@RestController
@RequestMapping("/function/topup")
public class SysTopUpController extends BaseController
{
    @Autowired
    private ISysTopUpService sysTopUpService;

    /**
     * 查询系统充值订单列表
     */
    @PreAuthorize("@ss.hasPermi('function:topup:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysTopUp sysTopUp)
    {
        startPage();
        List<SysTopUp> list = sysTopUpService.selectSysTopUpList(sysTopUp);
        return getDataTable(list);
    }

    /**
     * 导出系统充值订单列表
     */
    @PreAuthorize("@ss.hasPermi('function:topup:export')")
    @Log(title = "系统充值订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysTopUp sysTopUp)
    {
        List<SysTopUp> list = sysTopUpService.selectSysTopUpList(sysTopUp);
        ExcelUtil<SysTopUp> util = new ExcelUtil<SysTopUp>(SysTopUp.class);
        util.exportExcel(response, list, "系统充值订单数据");
    }

    /**
     * 获取系统充值订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('function:topup:query')")
    @GetMapping(value = "/{topUpId}")
    public AjaxResult getInfo(@PathVariable("topUpId") Long topUpId)
    {
        return success(sysTopUpService.selectSysTopUpByTopUpId(topUpId));
    }

    /**
     * 新增系统充值订单
     */
//    @PreAuthorize("@ss.hasPermi('function:topup:add')")
    @Log(title = "系统充值订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysTopUp sysTopUp)
    {
        return toAjax(sysTopUpService.insertSysTopUp(sysTopUp));
    }
    /**
     * 充值接口
     *
     * @return 唤起充值参数
     */
    @PostMapping("/topUp")
    public AjaxResult recharge(@Validated @RequestBody PayParam payParam) {
        return success(sysTopUpService.topUp(payParam));
    }

    /**
     * 退款
     */
    @PostMapping("/orderRefund")
    public AjaxResult orderRefund(@RequestBody Orders orders) {
        return toAjax(sysTopUpService.orderRefund(orders));
    }
    /**
     * 修改系统充值订单
     */
    @PreAuthorize("@ss.hasPermi('function:topup:edit')")
    @Log(title = "系统充值订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysTopUp sysTopUp)
    {
        return toAjax(sysTopUpService.updateSysTopUp(sysTopUp));
    }

    /**
     * 删除系统充值订单
     */
    @PreAuthorize("@ss.hasPermi('function:topup:remove')")
    @Log(title = "系统充值订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{topUpIds}")
    public AjaxResult remove(@PathVariable Long[] topUpIds)
    {
        return toAjax(sysTopUpService.deleteSysTopUpByTopUpIds(topUpIds));
    }




}
